package com.mjl.shops.utils;

import android.content.SharedPreferences;

import com.mjl.shops.base.ShopApp;

public class SharedUtils {

    private SharedPreferences sharedPreferences;

    private static SharedUtils sharedUtils;

    public static SharedUtils getInstance(){

        if (sharedUtils == null) {
            synchronized (SharedUtils.class) {
                if (sharedUtils == null) {
                    sharedUtils = new SharedUtils();
                }
            }
        }
        return sharedUtils;
    }

    private SharedUtils(){
        if (sharedPreferences == null){
            sharedPreferences = ShopApp.getInstance().getSharedPreferences("shop_shared", ShopApp.getInstance().MODE_PRIVATE);
        }
    }

    //保存字符串
    public void setString(String name,String value){
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(name,value);
        editor.commit();
    }

    //获取保存的字符串
    public String getString(String name,String def){
        return sharedPreferences.getString(name,def);
    }

}
